home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / init9akp.zoo / init.doc next >
Encoding:
Text File  |  1991-11-04  |  12.3 KB  |  324 lines

  1. This file is not an "official" part of MiNT, but please distribute it
  2. with init.prg.
  3.  
  4. This document describes the version of the "init" shell released
  5. 11/4/91 by Allan Pratt.
  6.  
  7. -----------------------------------------------------------------------
  8. init.prg: by Allan Pratt and Eric Smith
  9.  
  10. Here is a sample shell that can be used as init.prg for MiNT (if you like
  11. it; there's nothing special about this shell, and any other non-GEM program
  12. could be used, or gem.prg if you want GEM to start right away). This shell
  13. is useful mainly for its understanding of job control.
  14.  
  15. When started, init looks in the current directory for the file "init.rc";
  16. if this file is found, the lines in it are read and processed just as if
  17. they had been typed at the keyboard. A prompt is then printed, and lines
  18. are read from the keyboard until an end of file character (^D) is
  19. encountered. Commands on a line may be separated by the ";" character (in
  20. which case they are executed one after another), the "&" character (in
  21. which case they are executed concurrently), or by the "|" character (in
  22. which case they are executed concurrently with the standard output of the
  23. first command connected to the standard input of the second command). Any
  24. line starting with a "#" character is treated as a comment, and ignored.
  25.  
  26. External commands are searched for using the environment variable PATH,
  27. which should consist of directories separated by commas. See the sample
  28. init.rc for an example. Arguments are passed to external commands using the
  29. Atari extended argument passing convention.
  30.  
  31. I/O redirection is supported for external commands; to redirect the output
  32. of a command to a file, use "> file"; to append to a file use ">> file";
  33. and to redirect input from a file use "< file".  In addition, use ">& file"
  34. or ">>& file" to redirect both stdout and stderr to file, and "2> file" or
  35. "2>> file" to redirect just stderr.  "prog args 2> err > out" will redirect
  36. stderr to "err" and stdout to "out."
  37.  
  38. Command-line Arguments
  39. ============ =========
  40.  
  41.   -v        Causes all commands to be echoed to the screen before they're
  42.         executed.  See VERBOSITY.
  43.  
  44.   -s        Causes batch files to be aborted if a command in the batch 
  45.         file exits with nonzero $STATUS.  See BATCH_EXIT.
  46.  
  47.   -c args ...    All args after -c are collected into a line, and that line
  48.         is executed by the shell. Then the shell exits with that
  49.         command's $STATUS code.
  50.  
  51.  
  52. Variables
  53. =========
  54.  
  55. Variables are set with setenv, and are referenced by prefixing their names
  56. with a "$", e.g.:
  57.  
  58.    echo $PATH
  59.  
  60. will echo the value of the environment variable PATH. The name may be
  61. enclosed in parentheses or braces; thus
  62.  
  63.    setenv FOO foo
  64.    echo $(FOO)bar ${FOO}bar 
  65.  
  66. will echo "foobar foobar". If there are no
  67. parentheses or braces, the name of the environment variable ends with the
  68. first character not in the set [A-Za-z0-9_?*], so "echo $FOO\bar" yields
  69. "foo\bar" and "echo $FOO*" does not yield files matching "foo*" but rather
  70. the value of the variable 'FOO*'.
  71.  
  72. Typing "setenv" with no arguments will show the values of all environment
  73. variables.
  74.  
  75. The following variables have special meaning to the shell:
  76.  
  77.     $PATH: as mentioned above, is used to find programs.  Setting this
  78.     causes an automatic "rehash" (see below).
  79.  
  80.     $PROMPT: printed before each line of input in an interactive shell.
  81.  
  82.     $BATCH_EXIT: the value of this variable should be a number. When
  83.     nonzero, batch files (and even the shell itself) will exit when any
  84.     command returns a nonzero exit code.
  85.  
  86.     $VERBOSITY: when nonzero, all commands are displayed on the screen
  87.     after being alias-expanded, wildcard-expanded, and
  88.     variable-substituted, but before being executed.
  89.  
  90.     $NOTIFY: when nonzero, a message will be printed on your screen as
  91.     soon as a background job exits, rather than waiting until the next
  92.     time the shell prompt is printed.
  93.  
  94. In addition, the following things can be used like environment variables,
  95. but they are not truly in your environment:
  96.  
  97.     $CWD: yields your current working directory.
  98.  
  99.     $STATUS: yields the exit code of the last command or batch file.
  100.     (the exit code of a batch file is the exit code of the last command
  101.     executed from that batch file.)
  102.  
  103. If you use $ for variable-substitution on the command line and there is no
  104. variable with the name you give, an error message is printed and the
  105. command is not run.
  106.  
  107. Wildcards
  108. =========
  109.  
  110. It is possible to refer to a group of files with similar names by means of
  111. special characters ("wildcards"). For example, the pattern "*.c" means "all
  112. files that have the extension .c". Thus, if the current directory contains
  113. the files "foo", "foo.c", "bar.c", and "bar.doc", the command
  114.  
  115.     echo *.c
  116.  
  117. would be exactly equivalent to
  118.  
  119.     echo foo.c bar.c
  120.  
  121. and
  122.  
  123.     echo *c
  124.  
  125. would be the same as
  126.  
  127.     echo foo.c bar.c bar.doc
  128.  
  129. (Note that the files appear in their "true" order on the disk, not necessarily
  130. in alphabetical order).
  131.  
  132. The following wildcards are supported:
  133.  
  134. *:    matches any sequence of 0 or more characters
  135. ?:    matches any 1 character
  136. [...]:  matches one character inside the brackets; if two characters are
  137.     seperated by a minus sign ('-') then all characters between those
  138.     two are also matched
  139.  
  140. Examples:
  141.  
  142. [ad-gz]*    matches all files beginning with 'a', 'd', 'e', 'f', 'g', or
  143.         'z' (read as "(a, or d through g, or z) followed by anything").
  144.  
  145. *.*        matches all files containing a period. Note the difference
  146.         from some wildcard matching, in which '*.*' matches ALL files.
  147.  
  148. a*.[ch]        matches all files starting with 'a' and having an extension
  149.         of '.c' or '.h'.
  150.  
  151. If you have any wildcards in a command line, and none of them actually
  152. matches any files, an error message is printed and the command is not run.
  153.  
  154. Batch Files
  155. ===========
  156.  
  157. Init commands may be placed in a file with a ".bat" extension; typing the
  158. filename (with or without the ".bat" extension) will then run those
  159. commands.
  160.  
  161. Arguments to batch files are accessed in a way similar to environment
  162. variables: $1 yields the first argument to the batch file, $2 the second,
  163. and so on.  $0 yields the name of the batch file itself, $* yields all
  164. arguments from $1 on, $? yields the number of arguments, and the built-in
  165. command 'shift' shifts $3 to $2, $2 to $1, and so on, and decrements $?. 
  166. 'shift' leaves $0 alone.  Example of a simple batch file which executes the
  167. command named in its first argument, giving it the string "fixed_args" as
  168. its first argument and the rest of the batch-file command line as the rest
  169. of its args:
  170.  
  171.     echo This is batch file $0, which will execute the command $1.
  172.     setenv cmdHOLD $1
  173.     shift
  174.     $cmdHOLD fixed_args $*
  175.  
  176. Batch file arguments do nest, but each one is executed by the same shell,
  177. with the same environment and so on, so they can affect the global shell
  178. state (i.e. current directory, environment, aliases, etc.).  This is a lose
  179. and should be re-done.  In the meantime, if you want to execute a batch
  180. file in its own shell, use "init -c batch_file_name batch_file_args ..."
  181.  
  182. [Note to shell hackers: the ability to use $? relies on dollar substitution
  183. being done before wildcard substitution, because ? is a wildcard character.
  184. Also, the ability to use $? (and $STATUS) is useless without an "if"
  185. command.]
  186.  
  187. Version note: arguments to batch files are new as of 2/91.
  188.  
  189. Grubby details department: if a string starting with a digit gets to dollar
  190. substitution, atoi is called on it and that's what you get. The
  191. substitution for $1one is the first argument to the batch file, not
  192. getenv("1one").  If there is no Nth argument you get an error message.
  193.  
  194. Builtin Commands
  195. ================
  196.  
  197. The following commands are built in:
  198.  
  199. alias [string [command]]
  200.     With no arguments, prints a list of all aliases.
  201.     With one argument, shows what command the given string is aliased to.
  202.     With two or more arguments, the first argument ("string") becomes an
  203.     alias for the command consisting of all the other arguments. After this,
  204.     typing "string" is the same as typing that command.
  205.     Example:
  206.     alias c d:\bin\gcc.ttp -O -c
  207.     c foo.c
  208.     c bar.c
  209.     is the same as
  210.     d:\bin\gcc.ttp -O -c foo.c
  211.     d:\bin\gcc.ttp -O -c bar.c
  212.  
  213. bg [pid]
  214.     Restart the job with process group "pid", but leave it in the background.
  215.     If "pid" is omitted, the last job in the list of jobs is used.
  216.  
  217. cd [path]
  218.     Change the current directory to "path"; if no path is given, print
  219.     the current directory.
  220.  
  221. echo [-n] [args]
  222.     Print the given arguments (if any) on the standard output, followed by
  223.     a newline character.  Suppress the newline character if -n is present.
  224.  
  225. exit [code]
  226.     Leave the shell.  Exits with status code 'code' if present, else zero.
  227.  
  228. fg [pid]
  229.     Bring the job with process group "pid" to the foreground. The process
  230.     group is the number in brackets reported by the "jobs" command. If
  231.     "pid" is omitted, the last job in the list of jobs is used.
  232.  
  233. history [n]
  234.     Display the last N lines typed as shell commands.  With no argument,
  235.     displays them all.
  236.  
  237. jobs
  238.     Print a list of all jobs that the shell knows about.
  239.  
  240. kill [-sig] pid
  241.     Send the signal whose number is "sig" to process group "pid". The default
  242.     value for sig is 15 (SIGTERM); 9 (SIGKILL) is also useful, since it
  243.     cannot be caught or ignored.
  244.  
  245. rehash [-l] [-v]
  246.     Scans the directories listed in the PATH environment variable for
  247.     executable programs and batch files, and adds them to a "hash buffer"
  248.     so they can be found quickly when used as commands.  With -l, the hash
  249.     buffer is then  listed to stdout.  With -v, it prints statistics
  250.     (currently just the number of file names in each "hash bucket"). This
  251.     happens automatically when the shell finds a PATH in its initial
  252.     environment, and any time the environment variable PATH it set.
  253.  
  254. setenv [name [val]]
  255.     With no arguments, print the current environment; with one argument,
  256.     print the current value of that environment variable; with two arguments,
  257.     set the named variable to have value "val".
  258.  
  259. shift
  260.     Shifts the args to a batch file, such that the old $1 is lost, the new
  261.     $1 is the old $2, and so on.
  262.  
  263. which <name>
  264.     Prints the full pathname of the program or batch file which will be run
  265.     if <name> is used as a command, provided <name> is in the hash buffer. 
  266.     If it's not there, <name> itself is printed.
  267.  
  268. COMMAND-LINE EDITING AND HISTORY
  269. ================================
  270.  
  271. The command-line editing package is based on READLINE from Dave Clemans,
  272. seriously hacked by Allan Pratt.
  273.  
  274. As implemented in the shell, the readline package always uses Emacs-style
  275. editing.  This is because I do not use VI, and I could not adequately test
  276. the vi-style editing code in readline.
  277.  
  278. EMACS mode commands:
  279.  
  280.     (your terminal erase)    erase
  281.     ^N ^P ^B ^F ^A ^E    cursor movement    
  282.     ^H ^D ^K ^W ^Y DEL    delete, kill, yank, etc.
  283.     M-f M-b            move by words
  284.     M-d M-^H M-DEL        delete by words
  285.     ^Q            quote-char
  286.     ^L            retype line
  287.     M-w M-p            copy region
  288.     ^X^X            exchange-dot-and-mark
  289.     ^@ M-SPACE        set-mark
  290.     ^R ^S            search reverse, forward
  291.     ^K            kill to end of line
  292.     ^U M-^K M-^U        delete line
  293.     TAB M-ESC        expand name
  294.     M-^L            list possible expansions
  295.  
  296. (M-x means "Meta-x" or "press escape, then x," just like in Emacs.)
  297.  
  298. If you use ^S or ^R you enter "search mode."  What happens is that a line
  299. of input is read without echoing it, up until you hit Return or Escape. 
  300. Then it searches forward or backward looking for that string, and puts you
  301. on that line if it finds it.  If you type and nothing comes out, it could
  302. be that you hit ^S and readline() is reading your search string; hit ESC or
  303. Return to get back to the real world.
  304.  
  305. Lines in this context are commands you have entered in the past. From the
  306. shell prompt, ^P calls up the last command you executed.  ^P again calls up
  307. the line before that, and so on.
  308.  
  309. You can refer to history lines using the C Shell history syntax with the
  310. exclamation mark: !foo anywhere in a command string (unquoted) is replaced
  311. with the entire contents of the last command line that began with "foo." 
  312. This is the only kind of history substitution available.
  313.  
  314. There are 16 lines of history as shipped.
  315.  
  316. BUGS
  317. ====
  318.  
  319. The output of built-in commands and batch files may not be redirected.
  320.  
  321. When NOTIFY is set, a message is printed when foreground processes exit,
  322. not just when background processes exit.
  323.  
  324.